home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / ODF / OS / FWGraphx / FWFont.cpp < prev    next >
Encoding:
Text File  |  1996-12-16  |  8.7 KB  |  312 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWFont.cpp
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWFONT_H
  13. #include "FWFont.h"
  14. #endif
  15.  
  16. #ifndef FWGC_H
  17. #include "FWGC.h"
  18. #endif
  19.  
  20. #ifndef FWPOINT_H
  21. #include "FWPoint.h"
  22. #endif
  23.  
  24. #ifndef FWFXMATH_H
  25. #include "FWFxMath.h"
  26. #endif
  27.  
  28. #ifndef FWGRUTIL_H
  29. #include "FWGrUtil.h"
  30. #endif
  31.  
  32. #ifndef FWSTRMRW_H
  33. #include "FWStrmRW.h"
  34. #endif
  35.  
  36. // ----- Macintosh Includes -----
  37.  
  38. #if defined(FW_BUILD_MAC) && !defined(__TEXTUTILS__)
  39. #include <TextUtils.h>
  40. #endif
  41.  
  42. #if defined(FW_BUILD_MAC) && !defined(__FONTS__)
  43. #include <Fonts.h>
  44. #endif
  45.  
  46. #ifdef FW_BUILD_MAC
  47. #pragma segment FWGraphics_Font
  48. #endif
  49.  
  50. //========================================================================================
  51. //    Template instantiation
  52. //========================================================================================
  53.  
  54. #include "FWGrRef.tpp"
  55.  
  56. FW_DEFINE_AUTO_TEMPLATE(FW_TGrRefPtr, FW_HFont)
  57.  
  58. #ifdef FW_USE_TEMPLATE_PRAGMAS
  59.  
  60. #pragma template_access public
  61. #pragma template FW_TGrRefPtr<FW_HFont>
  62.  
  63. #else
  64.  
  65. template class FW_TGrRefPtr<FW_HFont>;
  66.  
  67. #endif
  68.  
  69. //========================================================================================
  70. //    class FW_CFont
  71. //========================================================================================
  72.  
  73. FW_DEFINE_AUTO(FW_CFont)
  74.  
  75. //----------------------------------------------------------------------------------------
  76. //    FW_PrivAcquireGrRep
  77. //----------------------------------------------------------------------------------------
  78.  
  79. void FW_PrivAcquireGrRep(FW_HFont rep)
  80. {
  81.     if (rep != 0)
  82.         FW_PrivFont_Acquire(rep);
  83. }
  84.  
  85. //----------------------------------------------------------------------------------------
  86. //    FW_PrivReleaseGrRep
  87. //----------------------------------------------------------------------------------------
  88.  
  89. void FW_PrivReleaseGrRep(FW_HFont rep)
  90. {
  91.     if (rep != 0)
  92.         FW_PrivFont_Release(rep);
  93. }
  94.  
  95. //----------------------------------------------------------------------------------------
  96. //    FW_CFont::FW_CFont
  97. //----------------------------------------------------------------------------------------
  98.  
  99. FW_CFont::FW_CFont(const FW_CString& fontName, FW_FontStyle fontStyle, FW_Fixed fontSize)
  100. {
  101.     FW_PlatformError error;
  102.     FW_HFont rep = FW_PrivFont_Create(fontName, fontStyle, fontSize, &error);
  103.     FW_FailOnError(error);
  104.     SetRep(rep);
  105.     FW_END_CONSTRUCTOR
  106. }
  107.  
  108. //----------------------------------------------------------------------------------------
  109. //    FW_CFont::FW_CFont
  110. //----------------------------------------------------------------------------------------
  111.  
  112. FW_CFont::FW_CFont(const FW_CFont& other) :
  113.     FW_TGrRefPtr<FW_HFont>(other)
  114. {
  115.     FW_END_CONSTRUCTOR
  116. }
  117.  
  118. //----------------------------------------------------------------------------------------
  119. //    FW_CFont::FW_CFont
  120. //----------------------------------------------------------------------------------------
  121.  
  122. FW_CFont::FW_CFont(FW_EStandardFonts std)
  123. {
  124.     FW_PlatformError error;
  125.     FW_HFont rep = FW_PrivFont_CreateStandard(std, &error);
  126.     FW_FailOnError(error);
  127.     SetRep(rep);
  128.     FW_END_CONSTRUCTOR
  129. }
  130.  
  131. //----------------------------------------------------------------------------------------
  132. //    FW_CFont::FW_CFont
  133. //----------------------------------------------------------------------------------------
  134.  
  135. FW_CFont::~FW_CFont()
  136. {
  137.     FW_START_DESTRUCTOR
  138. }
  139.  
  140. //----------------------------------------------------------------------------------------
  141. //    FW_CFont::operator=
  142. //----------------------------------------------------------------------------------------
  143.  
  144. FW_CFont& FW_CFont::operator=(const FW_CFont& other)
  145. {
  146.     FW_TGrRefPtr<FW_HFont>::operator=(other);
  147.     return *this;
  148. }
  149.  
  150. //----------------------------------------------------------------------------------------
  151. //    FW_CFont::operator=
  152. //----------------------------------------------------------------------------------------
  153.  
  154. FW_CFont& FW_CFont::operator=(FW_EStandardFonts std)
  155. {
  156.     FW_PlatformError error;
  157.     FW_HFont rep = FW_PrivFont_CreateStandard(std, &error);
  158.     FW_FailOnError(error);
  159.     SetRep(rep);
  160.     return *this;
  161. }
  162.  
  163. //----------------------------------------------------------------------------------------
  164. //    FW_CFont::GetFontName
  165. //----------------------------------------------------------------------------------------
  166.  
  167. void FW_CFont::GetFontName(FW_CString& fontName) const
  168. {
  169.     FW_PlatformError error;
  170.     FW_PrivFont_GetName(fRep, fontName, &error);
  171.     FW_FailOnError(error);
  172. }
  173.  
  174. //----------------------------------------------------------------------------------------
  175. //    FW_CFont::GetPlatformFontName
  176. //----------------------------------------------------------------------------------------
  177.  
  178. void FW_CFont::GetPlatformFontName(FW_CString& fontName) const
  179. {
  180. #ifdef FW_BUILD_MAC
  181.     // Get the actual name of the font
  182.     fontName = FW_MacGetFontName(MacGetFontID());
  183. #endif
  184. #ifdef FW_BUILD_WIN
  185.     // [MEB] To be done
  186.     GetFontName(fontName);    // for now
  187. #endif
  188. }
  189.  
  190. //----------------------------------------------------------------------------------------
  191. //    FW_CFont::SetFontName
  192. //----------------------------------------------------------------------------------------
  193.  
  194. void FW_CFont::SetFontName(const FW_CString& fontName)
  195. {
  196.     FW_PlatformError error;
  197.     FW_PrivFont_SetName(fRep, fontName, &error);
  198.     FW_FailOnError(error);
  199. }
  200.  
  201. //----------------------------------------------------------------------------------------
  202. //    FW_CFont::GetFontMetrics
  203. //----------------------------------------------------------------------------------------
  204.  
  205. void FW_CFont::GetFontMetrics(FW_HGDevice device, FW_CFontMetrics& fontMetrics) const
  206. {    
  207.     FW_FailOnError(FW_PrivGDev_GetFontMetrics(device, *this, fontMetrics));
  208. }
  209.  
  210. //----------------------------------------------------------------------------------------
  211. //    FW_CFont::GetFontMetrics
  212. //----------------------------------------------------------------------------------------
  213.  
  214. void FW_CFont::GetFontMetrics(FW_CGraphicContext& gc, FW_CFontMetrics& fontMetrics) const
  215. {
  216.     GetFontMetrics(gc.GetGraphicDevice(), fontMetrics);
  217. }
  218.  
  219. //----------------------------------------------------------------------------------------
  220. //    FW_CFont::Copy
  221. //----------------------------------------------------------------------------------------
  222.  
  223. FW_CFont FW_CFont::Copy() const
  224. {
  225.     FW_PlatformError error;
  226.     FW_HFont rep = FW_PrivFont_Copy(fRep, &error);
  227.     FW_FailOnError(error);
  228.     
  229.     FW_CFont font;
  230.     font.SetRep(rep);
  231.     return font;
  232. }
  233.  
  234. //----------------------------------------------------------------------------------------
  235. //    FW_CFont::PlatformToODFFontStyle
  236. //----------------------------------------------------------------------------------------
  237. //    It is a const& because on windows FW_PlatformFontStyle is a LOGFONT
  238.  
  239. FW_FontStyle FW_CFont::PlatformToODFFontStyle(const FW_PlatformFontStyle& platformStyle)
  240. {
  241.     FW_FontStyle fontStyle = FW_kPlain;
  242.  
  243. #ifdef FW_BUILD_MAC
  244.     if (platformStyle & bold)
  245.         fontStyle += FW_kBold;
  246.     if (platformStyle & italic)
  247.         fontStyle += FW_kItalic;
  248.     if (platformStyle & underline)
  249.         fontStyle += FW_kUnderline;
  250.     if (platformStyle & outline)
  251.         fontStyle += FW_kOutline;
  252.     if (platformStyle & shadow)
  253.         fontStyle += FW_kShadow;
  254.     if (platformStyle & extend)
  255.         fontStyle += FW_kExtended;
  256.     if (platformStyle & condense)
  257.         fontStyle += FW_kCondensed;
  258. #endif
  259.  
  260. #ifdef FW_BUILD_WIN
  261.     if (platformStyle.lfItalic != 0)
  262.         fontStyle += FW_kItalic;
  263.     if (platformStyle.lfUnderline != 0)
  264.         fontStyle += FW_kUnderline;
  265.     if (platformStyle.lfStrikeOut != 0)
  266.         fontStyle += FW_kStrikeOut;
  267.     if (platformStyle.lfWeight == FW_BOLD)
  268.         fontStyle += FW_kBold;
  269. #endif
  270.  
  271.     return fontStyle;
  272. }
  273.  
  274. #ifdef FW_BUILD_MAC
  275. //----------------------------------------------------------------------------------------
  276. //    FW_CFont::MacSetFontID
  277. //----------------------------------------------------------------------------------------
  278.  
  279. void FW_CFont::MacSetFontID(short macFontID)
  280. {
  281.     FW_PlatformError error;
  282.     FW_PrivFont_MacSetFontID(fRep, macFontID, &error);
  283.     FW_FailOnError(error);
  284. }
  285. #endif
  286.  
  287. //----------------------------------------------------------------------------------------
  288. //    operator <<
  289. //----------------------------------------------------------------------------------------
  290.  
  291. FW_CWritableStream& operator << (FW_CWritableStream& stream, const FW_CFont& font)
  292. {
  293.     FW_PlatformError error;
  294.     FW_PrivFont_Write(font.fRep, stream, &error);
  295.     FW_FailOnError(error);
  296.     return stream;
  297. }
  298.  
  299. //----------------------------------------------------------------------------------------
  300. //    operator >>
  301. //----------------------------------------------------------------------------------------
  302.  
  303. FW_CReadableStream& operator >> (FW_CReadableStream& stream, FW_CFont& font)
  304. {
  305.     FW_PlatformError error;
  306.     FW_HFont rep = FW_PrivFont_Read(stream, &error);
  307.     FW_FailOnError(error);
  308.     font.SetRep(rep);
  309.     return stream;
  310. }
  311.  
  312.